﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
    <meta http-equiv="expires" content="0" />
    <title>FaceCat</title>
</head>
<body>
    <canvas id="mycanvas" width="1000" height="700" style="position: fixed; left: 0px; top: 0px;"/>
    <script type="text/javascript" src="facecat.js"></script>
    <script type="text/javascript">
        let canvas = document.getElementById("mycanvas"); //绘图区域
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        let gPaint = new FCPaint(); //绘图对象
        gPaint.canvas = canvas;
        gPaint.defaultUIStyle = "dark";
        scaleCanvas(gPaint);
        //判断是否移动端
        gPaint.isMobile = isMobileMode();
        if (gPaint.isMobile) {
            gPaint.scaleFactorX = 2.5;
            gPaint.scaleFactorY = 2.5;
        }
        addDefaultEvent(canvas, gPaint);
        var points = new Array();
        function callAPI(cmd) {
            if (typeof (facecat) != 'undefined') {
                return facecat.callFaceCat(cmd);
            } else {
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.open("GET", "http://127.0.0.1:9962?" + cmd, false);
                xmlhttp.send(null);
                return xmlhttp.responseText;
            }
            //callAPI("func=fcscript&funcname=getChatData('1234','1234',-1);");
        }

        let paintDiv = new FCView();
        paintDiv.dock = "fill";
        paintDiv.backColor = "rgb(0,0,0)";
        addView(paintDiv, gPaint);
        updateViewDefault(gPaint.views);

        /*
        * 重绘背景的实现方法
        * view:视图
        * paint:绘图对象
        * clipRect:裁剪区域
        */
        gPaint.onPaint = function (view, paint, clipRect) {
            onPaintDefault(view, paint, clipRect);
            paint.beginPath();
            for (let i = 1; i < points.length; i++) {
                paint.addLine(points[i - 1].x, points[i - 1].y, points[i].x, points[i].y);
            }
            paint.drawPath("rgb(255,0,0)", 10, 0);
        };

        /*
        * 重绘边框的实现方法
        * view:视图
        * paint:绘图对象
        * clipRect:裁剪区域
        */
        gPaint.onPaintBorder = function (view, paint, clipRect) {
            onPaintBorderDefault(view, paint, clipRect);
        };

        /*
        * 重置大小
        */
        let resizeAll = function () {
            canvas.width = document.documentElement.clientWidth;
            canvas.height = document.documentElement.clientHeight;
            scaleCanvas(gPaint);
            updateViewDefault(gPaint.views);
            invalidate(gPaint);
        };

        /*
        * 监听大小改变
        */
        window.onresize = function () {
            resizeAll();
        };

        /*
        * 旋转监听
        */
        window.onorientationchange = function () {
            resizeAll();

        };

        //刷新界面
        invalidate(gPaint);

        let room = "1234";
        let pwd = "1234";
        let lastIndex = -1;

        /*
        * 检查绘图
        */
        let checkGridLogPaint = function () {
            let result = callAPI("func=fcscript&funcname=getChatData('" + room + "','" + pwd + "'," + lastIndex + ");");
            if (result.length > 0 && result != "-1,-1") {
                lastIndex = parseInt(result.substr(0, result.indexOf(",")));
                let content = result.substr(result.indexOf(",") + 1);
                if (content.indexOf("app_KLine") != -1) {
                    points = new Array();
                    content = content.substr(content.indexOf(":") + 1);
                    content = content.substr(0, content.indexOf("'"));
                    let strs = content.split(";");
                    for (let i = 0; i < strs.length; i++) {
                        let subStrs = strs[i].split(",");
                        let newPoint = new FCPoint(parseFloat(subStrs[0]) * paintDiv.size.cx, parseFloat(subStrs[1]) * paintDiv.size.cy);
                        points.push(newPoint);
                    }
                    invalidate(gPaint);
                }
            }
        };

        //启动秒表
        setInterval(checkGridLogPaint, 100);
    </script>
</body>
</html>
